package common.util;


import java.util.List;

import business.manage.dictionary.Dictionary;
import business.manage.dictionary.StaticDictionary;



public class CreateStaticCode {
	/**
	 * <select id="color0" name="childProductArguments[0].color">
											<option value="green">黄</option>
											<option value="red">红</option>
									</select>
	 * @param name
	 * @return
	 */
	public static String createSelect(String selectName,String key,String selectedArg){
		return createSelect(selectName, key, selectedArg,false);
	}
	
	public static String createSelect(String selectName,String key,String selectedArg,boolean defaultOption){
		List<Dictionary> dictList =  StaticDictionary.get(key);
		StringBuffer sb = new StringBuffer();
		sb.append("<select id='color0' name='"+selectName+"'>");
		if(defaultOption){
			sb.append("<option value=''>-----</option>");
		}
		if(dictList!=null&&dictList.size()>0){
			for(int i=0;i<dictList.size();i++){
				Dictionary dict = dictList.get(i);
				if(selectedArg==null||selectedArg.equals("")){
					if(i==0&&defaultOption==false){
						sb.append("<option value='"+dict.getCode()+"' selected>"+dict.getName()+"</option>");
					}else{
						sb.append("<option value='"+dict.getCode()+"'>"+dict.getName()+"</option>");
					}
				}else{
					if(selectedArg.equals(dict.getCode())){
						sb.append("<option value='"+dict.getCode()+"' selected>"+dict.getName()+"</option>");
					}else{
						sb.append("<option value='"+dict.getCode()+"'>"+dict.getName()+"</option>");
					}
				}
			}
		}
		sb.append("</select>");
		return sb.toString();
	}
}
